package br.unirio.brasileirao.interceptor;

import java.util.Map;

import br.unirio.brasileirao.model.Usuario;
import br.unirio.brasileirao.util.Const;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

public class AdminAuthenticationInterceptor implements Interceptor
{
	private static final long serialVersionUID = 4454739932859156587L;

	@Override
	public void init() {}

	@Override
	public void destroy() {}

	@Override
	public String intercept( ActionInvocation actionInvocation ) 
		throws Exception 
	{
		Map<String, Object> session = actionInvocation.getInvocationContext().getSession();
		Usuario usuario = (Usuario)session.get( Const.SESSION_USUARIO );

		if( usuario != null && usuario.isAdministrador() )
			return actionInvocation.invoke();
		else
			return Action.LOGIN;
	}

}
